In [1]:
import pandas as pd
# Font: https://www.kaggle.com/datasets/uom190346a/sleep-health-and-lifestyle-dataset
file = "data/Sleep_health_and_lifestyle_dataset.csv"
df = pd.read_csv(file)
df.head()
Out[1]:
| Person ID | Gender | Age | Occupation | Sleep Duration | Quality of Sleep | Physical Activity Level | Stress Level | BMI Category | Blood Pressure | Heart Rate | Daily Steps | Sleep Disorder | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 1 | Male | 27 | Software Engineer | 6.1 | 6 | 42 | 6 | Overweight | 126/83 | 77 | 4200 | NaN |
| 1 | 2 | Male | 28 | Doctor | 6.2 | 6 | 60 | 8 | Normal | 125/80 | 75 | 10000 | NaN |
| 2 | 3 | Male | 28 | Doctor | 6.2 | 6 | 60 | 8 | Normal | 125/80 | 75 | 10000 | NaN |
| 3 | 4 | Male | 28 | Sales Representative | 5.9 | 4 | 30 | 8 | Obese | 140/90 | 85 | 3000 | Sleep Apnea |
| 4 | 5 | Male | 28 | Sales Representative | 5.9 | 4 | 30 | 8 | Obese | 140/90 | 85 | 3000 | Sleep Apnea |
In [2]:
import plotly.express as px
# Creem un gràfic de coordenades paral·leles
fig = px.parallel_coordinates(df, color = df["Quality of Sleep"], dimensions=["Quality of Sleep", "Sleep Duration", "Stress Level", "Heart Rate", "Physical Activity Level", "Daily Steps"],
color_continuous_scale=px.colors.diverging.Spectral, title="Son saluable i estil de vida",)
fig.show()